package com.sscl.blesample.adapter.provider;


import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sscl.blesample.R;
import com.sscl.blesample.adapter.ServicesCharacteristicsListAdapter;
import com.sscl.blesample.adapter.entity.services_characteristics_list_entity.ServiceUuidItem;

import java.util.List;

/**
 * 服务UUID provider
 *
 * @author jackie
 */
public class ServiceUuidProvider extends BaseNodeProvider {
    @Override
    public int getItemViewType() {
        return ServicesCharacteristicsListAdapter.TYPE_SERVICE_UUID;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_expandable_service_uuid;
    }

    @Override
    public void convert(@NonNull BaseViewHolder baseViewHolder, BaseNode baseNode) {
        ServiceUuidItem serviceUuidItem = (ServiceUuidItem) baseNode;
        baseViewHolder.setText(android.R.id.text1, serviceUuidItem.getName())
                .setText(android.R.id.text2, serviceUuidItem.getUuid())
                .setImageResource(R.id.expanded, serviceUuidItem.isExpanded() ? R.drawable.arrow_b : R.drawable.arrow_r);
    }

    @Override
    public void convert(@NonNull BaseViewHolder helper, BaseNode item, @NonNull List<?> payloads) {
        ServiceUuidItem serviceUuidItem = (ServiceUuidItem) item;
        helper.setText(android.R.id.text1, serviceUuidItem.getName())
                .setText(android.R.id.text2, serviceUuidItem.getUuid())
                .setImageResource(R.id.expanded, serviceUuidItem.isExpanded() ? R.drawable.arrow_b : R.drawable.arrow_r);
    }
}
